package com.personal.controller;

import com.personal.controller.result.Result;
import com.personal.controller.result.BackCode;
import com.personal.domain.OccupancyApply;
import com.personal.service.OccupancyApplyService;

import com.personal.util.partDisplay.OccupancyApplyPart;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @projectName: smartCommunity_springboot
 * @package: com.personal.controller
 * @className: OccupancyApply
 * @author: bong~
 * @description: TODO
 * @date: 2023/8/9 9:58
 * @version: 1.0
 */

@RestController
@RequestMapping("/occupancyApply")
public class OccupancyApplyController{

    @Autowired
    private OccupancyApplyService occupancyApplyService;


    @GetMapping("/All")
    public Result selectAll(){

        List<OccupancyApply> list=occupancyApplyService.selectAll();
        return new Result(list!=null?BackCode.GET_OK:BackCode.GET_ERR,list);
    }
    @GetMapping("")
    public Result selectPartAll(){
        List<OccupancyApplyPart> list=occupancyApplyService.selectPartAll();
        return new Result(list!=null?BackCode.GET_OK:BackCode.GET_ERR,list);
    }
    @GetMapping("/search")
    public Result selectPartByKey(@RequestParam("name")String name,@RequestParam("type")String type){
        List<OccupancyApplyPart> list=occupancyApplyService.selectPartByKey(name,type);
        return new Result(list!=null?BackCode.GET_OK:BackCode.GET_ERR,list);
    }
    @PostMapping()
    public Result add(@RequestBody OccupancyApply apply){
        boolean flag=occupancyApplyService.add(apply);
        return new Result(flag?BackCode.SAVE_OK:BackCode.SAVE_ERR,flag);
    }

    @GetMapping("/updateData")
    public Result getDateData(@RequestParam("id")int id){
        OccupancyApply apply=occupancyApplyService.getUpdateData(id);
        return new Result(apply!=null?BackCode.SAVE_OK:BackCode.GET_ERR,apply);
    }
    @PutMapping()
    public Result update(@RequestBody OccupancyApply apply){
        boolean flag= occupancyApplyService.update(apply);
        return new Result(flag?BackCode.UPDATE_OK:BackCode.UPDATE_ERR,flag);
    }



    @DeleteMapping()
    public Result delete(@RequestParam List<Integer> ids){
        boolean flag=occupancyApplyService.delete(ids);
        return new Result(flag?BackCode.DELETE_OK:BackCode.DELETE_ERR,flag);
    }






}
